package logic

import (
	"encoding/json"
	"fmt"
	"github.com/gogap/logs"
	"strconv"
	"time"
	"yundian/internel/app/dao"
	"yundian/internel/app/helper"
	"yundian/internel/app/helper/request"
	"yundian/internel/app/helper/resphelper/placeresp"
	"yundian/internel/app/models/bulletin"
	"yundian/internel/app/models/comment"
	"yundian/internel/app/models/placemodel"
	"yundian/internel/app/models/usersteward"
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/dingo/global"
	"yundian/internel/pkg/notifications"
	"yundian/internel/pkg/utils"
)

type ShWxNotificationsLogic struct{}

func NewShWxNotificationsLogic() *ShWxNotificationsLogic {
	return &ShWxNotificationsLogic{}
}

func (logic *ShWxNotificationsLogic) InitNotificationsData(param *placemodel.PlacesServiceNotification) *placemodel.PlacesServiceNotification {
	//查询员工信息
	placesStaffOpenIds := dao.NewNotificationDaoDao().GetStaffOpenIdByPlaceId(param.PlaceId, param.NotificationType).Unwrap().([]placeresp.StaffBasicInfo)
	//查询网点通知方式
	placesConfigInfo := dao.NewNotificationDaoDao().GetPlacesNotificationConfig(param.PlaceId).Unwrap().(*placemodel.PlacesInformationConfig)

	// 默认公众号推送
	if placesConfigInfo.Type == 0 {
		placesConfigInfo.Type = 5
	}
	param.SendType = placesConfigInfo.Type

	//拼接内容信息
	param.Info, param.NoticeInfo = notifications.JointContentStr(param)

	//员工排班
	placesStaffOpenIds = notifications.NotificationOnDutyStaff(placesStaffOpenIds)

	if param.MakeTime == "" {
		param.MakeTime = "1970-01-01 00:00:00"
	}

	//param.Status = 3
	//param.MemberId = userId
	//param.MemberId = 1
	//param.SendType = placesConfigInfo.Type
	param.SendTime = time.Now().Format("2006-01-02 15:04:05")
	param.CreateTime = time.Now().Format("2006-01-02 15:04:05")
	param.UpdateTime = time.Now().Format("2006-01-02 15:04:05")

	//新增通知
	notificationInfo := dao.NewNotificationDaoDao().NotificationServiceInsert(param).Unwrap().(*placemodel.PlacesServiceNotification)
	param.Id = notificationInfo.Id
	switch placesConfigInfo.Type {

	case 1:
		//钉钉群机器人异步调用通知
		dingo.Task(logic.DingTalkGroupRobotNotifications, func() {}, param, placesStaffOpenIds, placesConfigInfo)
	case 2:
		//企业微信群机器人异步调用通知
		dingo.Task(logic.WeChatGroupRobotNotifications, func() {}, param, placesStaffOpenIds, placesConfigInfo)
	case 3:
		//钉钉异步调用通知
		dingo.Task(logic.DingTalkNotificationsData, func() {}, param, placesStaffOpenIds, placesConfigInfo)
	case 4:
		//微信企业异步调用通知
		dingo.Task(logic.WeChatGroupNotificationsData, func() {}, param, placesStaffOpenIds, placesConfigInfo)
	case 5:
		//公众号异步调用通知
		dingo.Task(logic.WeChatPublicNotificationsData, func() {}, param, placesStaffOpenIds, placesConfigInfo)
	}

	dingo.Task(logic.StaffInformMessage, func() {}, param, placesStaffOpenIds, placesConfigInfo)
	return notificationInfo
}

//公众号通知
func (logic *ShWxNotificationsLogic) WeChatPublicNotificationsData(param ...interface{}) {
	notificationModel := param[0].(*placemodel.PlacesServiceNotification)
	staffOpenIds := param[1].([]placeresp.StaffBasicInfo)
	//placesConfigInfo := param[2].(*placemodel.PlacesInformationConfig)

	//configInfo := map[string]interface{}{}
	//json.Unmarshal([]byte(placesConfigInfo.Config), &configInfo)

	//查询用户信息，网点
	for _, staffInfo := range staffOpenIds {
		data := map[string]interface{}{}
		templateMsg := &notifications.TemplateMsg{}
		tempData := &notifications.TemplateData{}

		templateMsg.ToUser = staffInfo.Openid
		templateMsg.TemplateID = global.Cfg.Wx.HotelNotificationsTemplate
		templateMsg.Data = tempData
		//templateMsg.URL = global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id)
		templateMsg.MiniProgram.AppID = "wx2e73f0573316f208"
		templateMsg.MiniProgram.PagePath = "pages/index/workDetails?nid=" + strconv.Itoa(notificationModel.Id)

		//设置模板推送信息
		tempData.First.Value = fmt.Sprintf(`%s 您好，客人正在呼叫服务`, notificationModel.PlaceName)
		tempData.Keyword1.Value = notificationModel.PlaceRoom
		tempData.Keyword4.Value = notificationModel.CreateTime
		tempData.Keyword5.Value = "待处理"
		tempData.Remark.Value = "感谢您的辛苦付出，请尽快安排服务。(点击详情查看完整内容)"

		//服务类型
		switch notificationModel.NotificationType {
		case 1:
			tempData.Keyword2.Value = "房间清扫"
			tempData.Keyword3.Value = "清扫房间服务"

		case 2:
			tempData.Keyword2.Value = "日常用品更换"
			tempData.Keyword3.Value = notificationModel.NoticeInfo

		case 3:
			tempData.Keyword2.Value = "维修服务"
			tempData.Keyword3.Value = notificationModel.NoticeInfo

		case 5:
			tempData.Keyword2.Value = "开票服务"
			tempData.Keyword3.Value = notificationModel.NoticeInfo

		case 6:
			tempData.Keyword2.Value = "续住服务"
			tempData.Keyword3.Value = notificationModel.NoticeInfo

		case 7:
			tempData.Keyword2.Value = "退房通知"
			tempData.Keyword3.Value = notificationModel.NoticeInfo

		case 9:
			tempData.Keyword2.Value = "好评有礼审核"
			tempData.Keyword3.Value = "需查看评论，完成审核"

		case 11:
			tempData.Keyword2.Value = "超市服务"
			tempData.Keyword3.Value = "需尽快配送"

		case 12:
			tempData.Keyword2.Value = "叫醒服务"
			tempData.Keyword3.Value = "需按时叫醒"

		case 13:
			tempData.First.Value = fmt.Sprintf(`%s 您好，售货机出货通知`, notificationModel.PlaceName)
			tempData.Keyword2.Value = "售货机补货通知"
			tempData.Keyword3.Value = "请在客人退房后，及时补货"
		}

		templateMsg.Data = tempData

		dataByte, _ := json.Marshal(templateMsg)
		json.Unmarshal(dataByte, &data)

		//调用通知
		//resp, err := notifications.WeChatPublicTemplateSend(data, configInfo["appKey"].(string), configInfo["appSecret"].(string), notificationModel.PlaceId)
		resp, err := notifications.WeChatPublicTemplateSend(data, global.Cfg.Wx.NotifiAppId, global.Cfg.Wx.NotifiAppSecret, notificationModel.PlaceId)
		//消息发送记录
		if resp.Errcode == 0 && err == nil {
			notificationRecordModel := &placemodel.PlacesServiceRecord{}
			notificationRecordModel.PlaceId = notificationModel.PlaceId
			notificationRecordModel.UserId = staffInfo.StaffId
			notificationRecordModel.Status = 4
			notificationRecordModel.CreateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.ServiceId = notificationModel.Id
			dao.NewNotificationDaoDao().InsertPlacesServiceRecord(notificationRecordModel)

			//修改通知状态
			serviceNotificationModel := &placemodel.PlacesServiceNotification{}
			serviceNotificationModel.Id = notificationModel.Id
			serviceNotificationModel.Status = 4
			dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
		} else {
			serviceNotificationModel := &placemodel.PlacesServiceNotification{}
			serviceNotificationModel.Id = notificationModel.Id
			serviceNotificationModel.Status = 2
			dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
		}
	}

}

//微信企业通知
func (logic *ShWxNotificationsLogic) WeChatGroupNotificationsData(param ...interface{}) {
	notificationModel := param[0].(*placemodel.PlacesServiceNotification)
	staffOpenIds := param[1].([]placeresp.StaffBasicInfo)
	placesConfigInfo := param[2].(*placemodel.PlacesInformationConfig)

	configInfo := map[string]interface{}{}
	json.Unmarshal([]byte(placesConfigInfo.Config), &configInfo)
	//查询用户信息，网点
	for _, staffInfo := range staffOpenIds {
		data := map[string]interface{}{}
		sendMsg := &notifications.WeChatGroupMsg{}
		//没有企业微信的ID时，用手机号去获取
		if staffInfo.GroupWeChatUserId == "" {
			groupWeChatUserId := notifications.WeChatGetUserIdByMobile(staffInfo.Phone, configInfo["appKey"].(string), configInfo["appSecret"].(string), notificationModel.PlaceId)
			m := &usersteward.StUserStaff{}
			m.GroupWeChatUserId = groupWeChatUserId
			dao.NewNotificationDaoDao().UpdatePlaceStaffUserId(m, staffInfo.Phone)
			sendMsg.ToUser = groupWeChatUserId
		} else {
			sendMsg.ToUser = staffInfo.GroupWeChatUserId
		}
		//设置模板推送信息
		//sendMsg.ToUser = "ChenYang"
		sendMsg.MsgType = "text"
		sendMsg.AgentId = int(configInfo["agentId"].(float64))

		//服务类型
		switch notificationModel.NotificationType {
		case 1:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，请求清扫服务。" + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"

		case 2:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，" + notificationModel.NoticeInfo + "等需要更换服务" + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"

		case 3:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，" + notificationModel.NoticeInfo + "等需要维修服务" + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"

		case 5:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，需要开票服务，开票信息：" + notificationModel.NoticeInfo + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"

		case 6: //续住
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，需要续住服务：" + notificationModel.NoticeInfo + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"

		case 7: //续住
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，需要退房服务：" + notificationModel.NoticeInfo + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"

		case 9:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，需要好评有礼审核：" + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"

		case 11:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，超市服务：" + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"

		case 12:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，叫醒服务：" + " \n <a href=" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ">查看详情</a>"
		}
		dataByte, _ := json.Marshal(sendMsg)
		json.Unmarshal(dataByte, &data)

		//调用通知
		resp, err := notifications.WeChatGroupNotificationsSend(data, configInfo["appKey"].(string), configInfo["appSecret"].(string), notificationModel.PlaceId)
		//消息发送记录
		if resp.Errcode == 0 && err == nil {
			notificationRecordModel := &placemodel.PlacesServiceRecord{}
			notificationRecordModel.PlaceId = notificationModel.PlaceId
			notificationRecordModel.UserId = staffInfo.StaffId
			notificationRecordModel.CreateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.ServiceId = notificationModel.Id
			dao.NewNotificationDaoDao().InsertPlacesServiceRecord(notificationRecordModel)

			//修改通知状态
			serviceNotificationModel := &placemodel.PlacesServiceNotification{}
			serviceNotificationModel.Id = notificationModel.Id
			serviceNotificationModel.Status = 4
			dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
		} else {
			serviceNotificationModel := &placemodel.PlacesServiceNotification{}
			serviceNotificationModel.Id = notificationModel.Id
			serviceNotificationModel.Status = 2
			dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
		}
	}
}

//微信企业群聊通知
func (logic *ShWxNotificationsLogic) WeChatGroupOfNotificationsData(param ...interface{}) {
	notificationModel := param[0].(placemodel.PlacesServiceNotification)
	staffOpenIds := param[1].([]placeresp.StaffBasicInfo)
	placesConfigInfo := param[2].(*placemodel.PlacesInformationConfig)
	configInfo := map[string]interface{}{}
	json.Unmarshal([]byte(placesConfigInfo.Config), &configInfo)
	//查询用户信息，网点
	for _, staffInfo := range staffOpenIds {
		data := map[string]interface{}{}
		sendMsg := &notifications.WeChatGroupOfMsg{}
		//设置模板推送信息
		sendMsg.ChatId = "ChenYang"
		sendMsg.MsgType = "text"
		//服务类型
		switch notificationModel.NotificationType {
		case 1:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，请求清扫服务。"

		case 2:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，请求日用品更换服务"

		case 3:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，请求维修服务"

		case 5:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，需要开票服务，开票信息：" + notificationModel.NoticeInfo

		case 6: //续住
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，" + notificationModel.Info + "等需要续住服务"

		case 7:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，需要退房服务：" + notificationModel.NoticeInfo

		case 9:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，需要好评有礼审核"

		case 11:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，超市服务"

		case 12:
			sendMsg.WeChatGroupMsgSendText.Content = notificationModel.PlaceRoom + "号，叫醒服务"
		}
		dataByte, _ := json.Marshal(sendMsg)
		json.Unmarshal(dataByte, &data)

		//调用通知
		resp, err := notifications.WeChatGroupNotificationsSend(data, configInfo["appKey"].(string), configInfo["appSecret"].(string), notificationModel.PlaceId)
		//消息发送记录
		if resp.Errcode == 200 && err != nil {
			notificationRecordModel := &placemodel.PlacesServiceRecord{}
			notificationRecordModel.PlaceId = notificationModel.PlaceId
			notificationRecordModel.UserId = staffInfo.StaffId
			notificationRecordModel.CreateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.ServiceId = notificationModel.PlaceId
			dao.NewNotificationDaoDao().InsertPlacesServiceRecord(notificationRecordModel)
		}
	}
}

//微信企业创建群聊
//func (logic *ShWxNotificationsLogic) WeChatCreateGroupChat(m *notifications.WeChatCreateGroupChatParam) notifications.ResCreateGroupChat {
//	data := map[string]interface{}{}
//	//m := &notifications.WeChatCreateGroupChatParam{}
//	////设置模板推送信息
//	//creatModel.ChatId = "test002101"
//	//creatModel.Name = "技术后端1"
//	//creatModel.UserList = []string{"ChenYang", "dingjianhui", "XiangJu"}
//	//creatModel.Owner = "dingjianhui"
//
//	dataByte, _ := json.Marshal(m)
//	json.Unmarshal(dataByte, &data)
//	//调用通知
//	resp, err := notifications.WeChatCreateGroupChat(data, 1)
//	if resp.Errmsg != "ok" && err != nil {
//		log.Panicln("微信企业创建群聊失败", err.Error())
//		return resp
//	}
//	return resp
//}

//钉钉通知
func (logic *ShWxNotificationsLogic) DingTalkNotificationsData(param ...interface{}) {
	notificationModel := param[0].(*placemodel.PlacesServiceNotification)
	staffOpenIds := param[1].([]placeresp.StaffBasicInfo)
	placesConfigInfo := param[2].(*placemodel.PlacesInformationConfig)

	configInfo := map[string]interface{}{}
	json.Unmarshal([]byte(placesConfigInfo.Config), &configInfo)

	//查询用户信息，网点
	for _, staffInfo := range staffOpenIds {
		data := map[string]interface{}{}
		sendMsg := &notifications.DingTalkMsg{}

		//没有钉钉的ID时，用手机号去获取
		if staffInfo.DingTalkUserId == "" {
			dingTalkUserId := notifications.DingTalkGetUserIdByMobile(staffInfo.Phone, configInfo["appKey"].(string), configInfo["appSecret"].(string), notificationModel.PlaceId)
			m := &usersteward.StUserStaff{}
			m.DingTalkUserId = dingTalkUserId
			dao.NewNotificationDaoDao().UpdatePlaceStaffUserId(m, staffInfo.Phone)
			sendMsg.UserIdList = dingTalkUserId
		} else {
			sendMsg.UserIdList = staffInfo.DingTalkUserId
		}
		sendMsg.DingTalkMsgText.MsgType = "markdown"
		sendMsg.AgentId = int(configInfo["agentId"].(float64))

		var sweep, daily, maintain, makeInvoice, stayOver, checkOut, comment, supermarket, wake string

		sweep = fmt.Sprintf("## 清扫服务  \n > %s号, 请求 清扫服务。"+"\n\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
		daily = fmt.Sprintf("## 日用服务  \n > %s号, %s 等需要更换服务。"+"\n\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
		maintain = fmt.Sprintf("## 维修服务  \n >  %s号, %s 等需要维修服务。"+"\n\n >  [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
		makeInvoice = fmt.Sprintf("## 开票服务 \n >  %s号,  需要开票服务，开票信息： %s"+"\n\n >  [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
		stayOver = fmt.Sprintf("## 续住服务   \n > %s号,  需要续住服务： %s"+"\n\n >  [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
		checkOut = fmt.Sprintf("## 退房服务 \n >  %s号,  需要退房服务： %s"+"\n\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
		comment = fmt.Sprintf("## 好评有礼审核 \n >  %s号,  需要好评有礼审核： %s"+"\n\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
		supermarket = fmt.Sprintf("## 客房超市 \n >  %s号,  需要客房超市服务： %s"+"\n\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
		wake = fmt.Sprintf("## 叫醒服务 \n >  %s号,  需要叫醒服务： %s"+"\n\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))

		//服务类型
		switch notificationModel.NotificationType {
		case 1:
			//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，请求清扫服务。"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "清扫服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = sweep

		case 2:
			//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，" + notificationModel.NoticeInfo + "等需要更换服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "日用服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = daily

		case 3:
			//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，" + notificationModel.NoticeInfo + "等需要维修服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "维修服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = maintain

		case 5:
			//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，需要开票服务，开票信息：" + notificationModel.NoticeInfo
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "开票服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = makeInvoice

		case 6: //续住
			//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，需要续住服务：" + notificationModel.NoticeInfo
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "续住服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = stayOver

		case 7: //退房
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "退房服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = checkOut

		case 9:
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "好评有礼审核"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = comment

		case 11:
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "客房超市"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = supermarket

		case 12:
			sendMsg.DingTalkMsgText.DingTalkMsgText.Title = "叫醒服务"
			sendMsg.DingTalkMsgText.DingTalkMsgText.Content = wake
		}
		//sendMsg.Text.Content = "208" + "号房间，请求清扫服务。"

		configInfo := map[string]interface{}{}

		json.Unmarshal([]byte(placesConfigInfo.Config), &configInfo)

		dataByte, _ := json.Marshal(sendMsg)
		json.Unmarshal(dataByte, &data)

		//调用通知
		resp, err := notifications.DingTalkNotificationsSend(data, configInfo["appKey"].(string), configInfo["appSecret"].(string), notificationModel.PlaceId)
		//消息发送记录
		if resp.Errcode == 0 && err == nil {
			notificationRecordModel := &placemodel.PlacesServiceRecord{}
			notificationRecordModel.PlaceId = notificationModel.PlaceId
			notificationRecordModel.UserId = staffInfo.StaffId
			notificationRecordModel.Status = 4
			notificationRecordModel.CreateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.ServiceId = notificationModel.Id
			dao.NewNotificationDaoDao().InsertPlacesServiceRecord(notificationRecordModel)

			//修改通知状态
			serviceNotificationModel := &placemodel.PlacesServiceNotification{}
			serviceNotificationModel.Id = notificationModel.Id
			serviceNotificationModel.Status = 4
			dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
		} else {
			serviceNotificationModel := &placemodel.PlacesServiceNotification{}
			serviceNotificationModel.Id = notificationModel.Id
			serviceNotificationModel.Status = 2
			dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
		}
	}
}

//钉钉群通知
func (logic *ShWxNotificationsLogic) DingTalkGroupNotificationsData(param ...interface{}) {
	notificationModel := param[0].(placemodel.PlacesServiceNotification)
	staffOpenIds := param[1].([]placeresp.StaffBasicInfo)
	placesConfigInfo := param[2].(*placemodel.PlacesInformationConfig)

	//获取配置信息
	configInfo := map[string]interface{}{}
	json.Unmarshal([]byte(placesConfigInfo.Config), &configInfo)

	//查询用户信息，网点
	for _, staffInfo := range staffOpenIds {
		data := map[string]interface{}{}
		sendMsg := &notifications.DingTalkGroupMsg{}
		//设置模板推送信息
		sendMsg.ChatId = staffInfo.Openid
		sendMsg.DingTalkMsgText.MsgType = "text"

		//服务类型
		switch notificationModel.NotificationType {
		case 1:
			sendMsg.DingTalkMsgText.Text.Content = notificationModel.PlaceRoom + "号，请求清扫服务。"

		case 2:
			sendMsg.DingTalkMsgText.Text.Content = notificationModel.PlaceRoom + "号，请求日用品更换服务"

		case 3:
			sendMsg.DingTalkMsgText.Text.Content = notificationModel.PlaceRoom + "号，请求维修服务"

		case 6:
			sendMsg.DingTalkMsgText.Text.Content = notificationModel.PlaceRoom + "号，" + notificationModel.Info + "等需要续住服务"

		case 7:
			sendMsg.DingTalkMsgText.Text.Content = notificationModel.PlaceRoom + "号，需要退房服务：" + notificationModel.NoticeInfo

		case 9:
			sendMsg.DingTalkMsgText.Text.Content = notificationModel.PlaceRoom + "号，需要好评有礼审核"

		case 11:
			sendMsg.DingTalkMsgText.Text.Content = notificationModel.PlaceRoom + "号，超市服务"

		case 12:
			sendMsg.DingTalkMsgText.Text.Content = notificationModel.PlaceRoom + "号，叫醒服务"
		}
		dataByte, _ := json.Marshal(sendMsg)
		json.Unmarshal(dataByte, &data)

		//调用通知
		resp, err := notifications.DingTalkGroupOfNotificationsSend(data, configInfo["appKey"].(string), configInfo["appSecret"].(string), notificationModel.PlaceId)
		//消息发送记录
		if resp.Errcode == 200 && err != nil {
			notificationRecordModel := &placemodel.PlacesServiceRecord{}
			notificationRecordModel.PlaceId = notificationModel.PlaceId
			//notificationRecordModel.UserId = staffInfo.UserId
			notificationRecordModel.CreateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.ServiceId = notificationModel.PlaceId
			dao.NewNotificationDaoDao().InsertPlacesServiceRecord(notificationRecordModel)
		}
	}
}

//钉钉创建群聊
//func (logic *ShWxNotificationsLogic) DingTalkCreateGroupChat(m *notifications.DingTalkChatCreateParam) notifications.DingTalkChatCreateResp {
//	data := map[string]interface{}{}
//	dataByte, _ := json.Marshal(m)
//	json.Unmarshal(dataByte, &data)
//	//调用通知
//	resp, err := notifications.DingTalkCreateGroupChat(data, 1)
//	if resp.Errmsg != "ok" && err != nil {
//		log.Panicln("微信企业创建群聊失败", err.Error())
//		return resp
//	}
//	//是否存将群聊ID入库
//
//	return resp
//}

//服务信息添加
func (logic *ShWxNotificationsLogic) ServiceDataInfoInsert(m placemodel.PlacesServiceNotification) {

}

//企业微信群机器人通知
func (logic *ShWxNotificationsLogic) WeChatGroupRobotNotifications(param ...interface{}) {
	notificationModel := param[0].(*placemodel.PlacesServiceNotification)
	staffOpenIds := param[1].([]placeresp.StaffBasicInfo)
	placesConfigInfo := param[2].(*placemodel.PlacesInformationConfig)

	var mentionedMobile []string
	for _, staffInfo := range staffOpenIds {
		//消息发送记录
		mentionedMobile = append(mentionedMobile, staffInfo.Phone)
	}

	data := map[string]interface{}{}
	sendMsg := &notifications.WeChatGroupRobotMsg{}
	//设置模板推送信息

	sendMsg.MsgType = "markdown"

	var sweep, daily, maintain, makeInvoice, stayOver, checkOut, comment, supermarket, wake string

	sweep = fmt.Sprintf("# 清扫服务 \n"+"<font color=\"warning\">  %s号 </font>"+"请求清扫服务。"+"\n [查看详情](%s)", notificationModel.PlaceRoom, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	daily = fmt.Sprintf("# 日用品更换服务 \n"+"<font color=\"warning\"> %s号"+"</font>  %s 等需要日用品更换服务"+"\n [查看详情](%s)", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	maintain = fmt.Sprintf("# 维修服务 \n"+"<font color=\"warning\"> %s号"+"</font>  %s 等需要维修服务"+"\n [查看详情](%s)", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	makeInvoice = fmt.Sprintf("# 开票服务 \n"+"<font color=\"warning\"> %s号"+"</font>  需要开票服务，开票信息： %s"+"\n [查看详情](%s)", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	stayOver = fmt.Sprintf("# 续住服务 \n"+"<font color=\"warning\"> %s号"+"</font>  需要续住服务： %s"+"\n [查看详情](%s)", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	checkOut = fmt.Sprintf("# 退房服务 \n "+"<font color=\"warning\">  %s号 "+"</font>  需要退房服务： %s"+"\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	comment = fmt.Sprintf("# 好评有礼审核 \n "+"<font color=\"warning\">  %s号 "+"</font>  需要好评有礼审核： %s"+"\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	supermarket = fmt.Sprintf("# 客房超市服务 \n "+"<font color=\"warning\">  %s号 "+"</font>  需要客房超市服务： %s"+"\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	wake = fmt.Sprintf("# 叫醒服务 \n "+"<font color=\"warning\">  %s号 "+"</font>  需要叫醒服务： %s"+"\n > [查看详情](%s) \n >", notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))

	//服务类型
	switch notificationModel.NotificationType {
	case 1:
		sendMsg.WeChatGroupRobotMsgSendText.Content = sweep
		//sendMsg.WeChatGroupRobotMsgSendText.Content = "# 清扫 \n" + "<font color=\"warning\">" + notificationModel.PlaceRoom + "号" + "</font>" + "请求<font color=\"warning\">清扫服务</font>。" + "\n [查看详情](" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ")"

	case 2:
		sendMsg.WeChatGroupRobotMsgSendText.Content = daily
		//sendMsg.WeChatGroupRobotMsgSendText.Content = "# 日用 \n" + "<font color=\"warning\">" + notificationModel.PlaceRoom + "号" + "</font>" + notificationModel.NoticeInfo + "等需要更换服务" + "\n [查看详情](" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ")"

	case 3:
		sendMsg.WeChatGroupRobotMsgSendText.Content = maintain
		//sendMsg.WeChatGroupRobotMsgSendText.Content = "# 维修 \n" + notificationModel.PlaceRoom + "号，" + notificationModel.NoticeInfo + "等需要维修服务" + "\n [查看详情](" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ")"

	case 5:
		//sendMsg.WeChatGroupRobotMsgSendText.Content = "### 开票测试"
		sendMsg.WeChatGroupRobotMsgSendText.Content = makeInvoice
		//sendMsg.WeChatGroupRobotMsgSendText.Content = "# 开票 \n" + notificationModel.PlaceRoom + "号，需要开票服务，开票信息：" + notificationModel.NoticeInfo + "\n [查看详情](" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ")"

	case 6: //续住
		sendMsg.WeChatGroupRobotMsgSendText.Content = stayOver
		//sendMsg.WeChatGroupRobotMsgSendText.Content = "# 续住 \n" + notificationModel.PlaceRoom + "号，需要续住服务：" + notificationModel.NoticeInfo + "\n [查看详情](" + global.Cfg.Wx.WeChatPublicNotificationsURL + strconv.Itoa(notificationModel.Id) + ")"
	case 7:
		sendMsg.WeChatGroupRobotMsgSendText.Content = checkOut

	case 9:
		sendMsg.WeChatGroupRobotMsgSendText.Content = comment

	case 11:
		sendMsg.WeChatGroupRobotMsgSendText.Content = supermarket

	case 12:
		sendMsg.WeChatGroupRobotMsgSendText.Content = wake
	}
	//sendMsg.Text.Content = "208" + "号房间，请求清扫服务。"
	sendMsg.WeChatGroupRobotMsgSendText.MentionedMobileList = mentionedMobile

	configInfo := map[string]interface{}{}

	json.Unmarshal([]byte(placesConfigInfo.Config), &configInfo)

	dataByte, _ := json.Marshal(sendMsg)
	json.Unmarshal(dataByte, &data)
	//调用通知
	resp, err := notifications.WeChatGroupRobotNotificationsSend(data, configInfo["url"].(string))
	if resp.Errcode == 0 && err == nil {
		for _, staffInfo := range staffOpenIds {
			notificationRecordModel := &placemodel.PlacesServiceRecord{}
			notificationRecordModel.PlaceId = notificationModel.PlaceId
			notificationRecordModel.UserId = staffInfo.StaffId
			notificationRecordModel.Status = 4
			notificationRecordModel.CreateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.ServiceId = notificationModel.Id
			dao.NewNotificationDaoDao().InsertPlacesServiceRecord(notificationRecordModel)

			//修改通知状态
			serviceNotificationModel := &placemodel.PlacesServiceNotification{}
			serviceNotificationModel.Id = notificationModel.Id
			serviceNotificationModel.Status = 4
			dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
		}

	} else {
		serviceNotificationModel := &placemodel.PlacesServiceNotification{}
		serviceNotificationModel.Id = notificationModel.Id
		serviceNotificationModel.Status = 2
		dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
	}
}

//钉钉群机器人通知
func (logic *ShWxNotificationsLogic) DingTalkGroupRobotNotifications(param ...interface{}) {
	notificationModel := param[0].(*placemodel.PlacesServiceNotification)
	staffOpenIds := param[1].([]placeresp.StaffBasicInfo)
	placesConfigInfo := param[2].(*placemodel.PlacesInformationConfig)

	aiTeStr := ""
	var mentionedMobile []string
	for i, staffInfo := range staffOpenIds {
		if i+1 != len(staffOpenIds) {
			aiTeStr += "@" + staffInfo.Phone + ","
		} else {
			aiTeStr += "@" + staffInfo.Phone
		}
		//消息发送记录
		mentionedMobile = append(mentionedMobile, staffInfo.Phone)
	}

	data := map[string]interface{}{}
	sendMsg := &notifications.DingTalkGroupRobotMsgSend{}
	//设置模板推送信息

	sendMsg.MsgType = "markdown"

	var sweep, daily, maintain, makeInvoice, stayOver, checkOut, comment, supermarket, wake string

	sweep = fmt.Sprintf("## 清扫服务 \n > %s \n > %s号, 请求 清扫服务。"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	daily = fmt.Sprintf("## 日用服务 \n > %s \n > %s号, %s 等需要更换服务。"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	maintain = fmt.Sprintf("## 维修服务 \n > %s \n >  %s号, %s 等需要维修服务。"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	makeInvoice = fmt.Sprintf("## 开票服务 \n > %s \n >  %s号,  需要开票服务，开票信息： %s"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	stayOver = fmt.Sprintf("## 续住服务 \n > %s  \n > %s号,  需要续住服务： %s"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	checkOut = fmt.Sprintf("## 退房服务 \n > %s  \n > %s号,  需要退房服务： %s"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	comment = fmt.Sprintf("## 好评有礼审核 \n > %s  \n > %s号,  需要好评有礼审核： %s"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	supermarket = fmt.Sprintf("## 客房超市服务 \n > %s  \n > %s号,  需要客房超市服务： %s"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))
	wake = fmt.Sprintf("## 叫醒服务 \n > %s  \n > %s号,  需要叫醒服务： %s"+"\n\n > [查看详情](%s) \n >", aiTeStr, notificationModel.PlaceRoom, notificationModel.NoticeInfo, global.Cfg.Wx.WeChatPublicNotificationsURL+strconv.Itoa(notificationModel.Id))

	//服务类型
	switch notificationModel.NotificationType {
	case 1:
		//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，请求清扫服务。"
		sendMsg.Text.Title = "清扫服务"
		sendMsg.Text.Content = sweep

	case 2:
		//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，" + notificationModel.NoticeInfo + "等需要更换服务"
		sendMsg.Text.Title = "日用服务"
		sendMsg.Text.Content = daily

	case 3:
		//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，" + notificationModel.NoticeInfo + "等需要维修服务"
		sendMsg.Text.Title = "维修服务"
		sendMsg.Text.Content = maintain

	case 5:
		//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，需要开票服务，开票信息：" + notificationModel.NoticeInfo
		sendMsg.Text.Title = "开票服务"
		sendMsg.Text.Content = makeInvoice

	case 6: //续住
		//sendMsg.Text.Content = notificationModel.PlaceRoom + "号，需要续住服务：" + notificationModel.NoticeInfo
		sendMsg.Text.Title = "续住服务"
		sendMsg.Text.Content = stayOver

	case 7:
		sendMsg.Text.Title = "退房服务"
		sendMsg.Text.Content = checkOut

	case 9:
		sendMsg.Text.Title = "好评有礼审核"
		sendMsg.Text.Content = comment

	case 11:
		sendMsg.Text.Title = "客房超市服务"
		sendMsg.Text.Content = supermarket

	case 12:
		sendMsg.Text.Title = "叫醒服务"
		sendMsg.Text.Content = wake
	}
	//sendMsg.Text.Content = "208" + "号房间，请求清扫服务。"
	sendMsg.At.AtMobiles = mentionedMobile

	configInfo := map[string]interface{}{}

	json.Unmarshal([]byte(placesConfigInfo.Config), &configInfo)

	dataByte, _ := json.Marshal(sendMsg)
	json.Unmarshal(dataByte, &data)
	//调用通知

	urlStr := notifications.DingTalkRobotUrl(configInfo["secret"].(string), configInfo["url"].(string))
	//调用通知
	resp, err := notifications.DinTalkGroupRobotNotificationsSend(data, urlStr)

	//如果通知失败修改通知状态
	if resp.Errcode == 0 && err == nil {
		for _, staffInfo := range staffOpenIds {
			notificationRecordModel := &placemodel.PlacesServiceRecord{}
			notificationRecordModel.PlaceId = notificationModel.PlaceId
			notificationRecordModel.UserId = staffInfo.StaffId
			notificationRecordModel.Status = 4
			notificationRecordModel.CreateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
			notificationRecordModel.ServiceId = notificationModel.Id
			dao.NewNotificationDaoDao().InsertPlacesServiceRecord(notificationRecordModel)

			//修改通知状态
			serviceNotificationModel := &placemodel.PlacesServiceNotification{}
			serviceNotificationModel.Id = notificationModel.Id
			serviceNotificationModel.Status = 4
			dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
		}

	} else {
		serviceNotificationModel := &placemodel.PlacesServiceNotification{}
		serviceNotificationModel.Id = notificationModel.Id
		serviceNotificationModel.Status = 2
		dao.NewNotificationDaoDao().UpdatePlaceServiceNotification(serviceNotificationModel)
	}

}

// 站内通知记录
func (logic *ShWxNotificationsLogic) StaffInformMessage(param ...interface{}) {
	notificationModel := param[0].(*placemodel.PlacesServiceNotification)
	staffOpenIds := param[1].([]placeresp.StaffBasicInfo)
	var InsertList []*bulletin.StaffInformMessageDb
	title := `您有%d条最新“新服务提醒”待处理！`
	message := title + `请立即前往工单列表查看！`

	for _, item := range staffOpenIds {
		var nTypeList []int
		_ = json.Unmarshal([]byte(item.MessageTypes), &nTypeList)
		tParam := &request.StewardAppGetServiceNumReq{
			LoginUserId:  item.StaffId,
			Status:       helper.TypeNumNotificationStatusPending,
			PlaceId:      notificationModel.PlaceId,
			MessageTypes: nTypeList,
		}
		num := dao.NewNotificationDaoDao().GetAppNotificationServiceInfoTotal(tParam).Unwrap().(*request.StewardAppGetServiceNumRes).Num
		if num == 0 {
			continue
		}
		InsertList = append(InsertList, &bulletin.StaffInformMessageDb{
			Status:  helper.TypeNumCommonStatusFalse,
			PlaceId: notificationModel.PlaceId,
			Message: fmt.Sprintf(message, num),
			Title:   fmt.Sprintf(title, num),
			StaffId: item.StaffId,
			Type:    2,
		})
	}
	if data := dao.NewBulletinDao().InsertAppStaffInformMessage(InsertList); data.Err != nil {
		logs.Error("StaffInformMessage", data.Err)
	}
}

//企业微信群机器人通知(门店审核)
func (logic *ShWxNotificationsLogic) WeChatGroupRobotNotificationsByPlace(param ...interface{}) {
	// 获取门店信息
	//placeId := 445849
	placeId := param[0].(int)
	placeInfo := dao.NewPlaceDao().GetPlaceUserInfo(placeId).Unwrap().(*placeresp.PlaceInfo)

	webhook := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a323c523-3dfd-4ae9-83e7-8f8b08bc3bef"
	sendMsg := &notifications.WeChatGroupRobotMsg{}
	sendMsg.MsgType = "markdown"

	a := `新门店<font color="warning">【%s】</font>已提交审核，请相关同事注意。`
	b := `>门店名称: <font color="comment">%s</font>`
	c := `>门店地址: <font color="comment">%s</font>`
	d := `>联系人: <font color="comment">%s</font>`
	e := `>手机号码: <font color="comment">%s</font>`
	f := `>门店分成: <font color="comment">%d</font>`
	g := `[营业执照](%s)`

	address := utils.Join(placeInfo.Province, placeInfo.City, placeInfo.Country, placeInfo.Address)

	welcome := fmt.Sprintf(a, placeInfo.PlaceName)
	placeName := fmt.Sprintf(b, placeInfo.PlaceName)
	placeAddress := fmt.Sprintf(c, address)
	userName := fmt.Sprintf(d, placeInfo.Name)
	phone := fmt.Sprintf(e, placeInfo.Phone)
	profit := fmt.Sprintf(f, placeInfo.ProfitProportion)
	placeLicense := fmt.Sprintf(g, placeInfo.PlaceLicense)

	content := utils.Join(welcome, "\n", placeName, "\n", placeAddress, "\n", userName, "\n", phone, "\n", profit, "\n", ">", "\n", placeLicense)

	sendMsg.WeChatGroupRobotMsgSendText.Content = content
	dataByte, _ := json.Marshal(sendMsg)
	data := map[string]interface{}{}
	json.Unmarshal(dataByte, &data)

	//调用通知
	resp, err := notifications.WeChatGroupRobotNotificationsSend(data, webhook)
	if resp.Errcode == 0 && err == nil {
		logs.Info("发送成功")
	} else {
		logs.Info("发送失败", err)
	}

}

// 好评有礼审核成功机器人通知
func (logic *ShWxNotificationsLogic) WeChatGroupRobotNotificationsByHotelGoodsCommit(param ...interface{}) {
	commentId := param[0].(int)
	commentInfo := dao.NewNotificationDaoDao().GetCommentNotificationByCommentId(commentId).Unwrap().(*comment.ThirdCommentInfoWithAddressAndService)
	webhook := "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=f64b4672-4687-4650-8a74-34663185fae5"
	sendMsg := &notifications.WeChatGroupRobotMsg{}
	sendMsg.MsgType = "markdown"

	a := `门店<font color="warning">【%s】</font>下的【好评有礼】已通过审核，请相关同事注意。`
	b := `>门店名称: <font color="comment">%s</font>`
	c := `>房间号: <font color="comment">%s</font>`
	d := `>设备号: <font color="comment">%s</font>`
	e := `>应用: <font color="comment">%s</font>`
	f := `>第三方订单号: <font color="comment">%s</font>`
	g := `>兑换商品: <font color="comment">%s</font>`
	h := `>好评备注: <font color="comment">%s</font>`
	i := `>顾客姓名: <font color="comment">%s</font>`
	j := `>顾客手机号: <font color="comment">%s</font>`
	k := `>顾客收货地址: <font color="comment">%s</font>`
	l := `[商品图片](%s)`
	m := `[好评图片](%s)`

	// https://img.cnman.cn/

	adderssDetail := utils.Join(commentInfo.ProvinceName, commentInfo.CityName, commentInfo.CountyName, commentInfo.Address)
	welcome := fmt.Sprintf(a, commentInfo.PlaceName)
	placeName := fmt.Sprintf(b, commentInfo.PlaceName)
	placeRoom := fmt.Sprintf(c, commentInfo.PlaceRoom)
	deviceSn := fmt.Sprintf(d, commentInfo.DeviceSn)
	appName := fmt.Sprintf(e, commentInfo.AppName)
	outTradeNo := fmt.Sprintf(f, commentInfo.ThirdOrder)
	goodsName := fmt.Sprintf(g, commentInfo.GoodsName)
	message := fmt.Sprintf(h, commentInfo.Message)
	userName := fmt.Sprintf(i, commentInfo.Name)
	phone := fmt.Sprintf(j, commentInfo.Phone)
	address := fmt.Sprintf(k, adderssDetail)
	goodsIcon := fmt.Sprintf(l, "https://img.cnman.cn"+commentInfo.Icon)

	var commentImgs string
	var imgs []string
	//logs.Info(commentInfo.ImgList)
	json.Unmarshal([]byte(commentInfo.ImgList), &imgs)
	logs.Info(imgs)
	for _, lst := range imgs {
		commentImgs = utils.Join(commentImgs, "\n", ">", "\n", fmt.Sprintf(m, lst))
	}

	content := utils.Join(welcome, "\n", placeName, "\n", placeRoom, "\n", deviceSn, "\n",
		appName, "\n", outTradeNo, "\n", goodsName, "\n", message, "\n", userName, "\n", phone, "\n", address, "\n", ">", "\n", goodsIcon, "\n", ">", "\n", commentImgs)
	logs.Info("好评有礼通知内容", content, webhook)
	sendMsg.WeChatGroupRobotMsgSendText.Content = content
	dataByte, _ := json.Marshal(sendMsg)
	data := map[string]interface{}{}
	json.Unmarshal(dataByte, &data)

	//调用通知
	resp, err := notifications.WeChatGroupRobotNotificationsSend(data, webhook)
	if resp.Errcode == 0 && err == nil {
		logs.Info("发送成功")
	} else {
		logs.Info("发送失败", err)
	}

}
